/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.raflik.queryxml.lib;

import java.util.HashMap;
import java.util.Map;
import org.openide.util.NbBundle;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;

/**
 *
 * @author raflik
 */
public enum ResultType {
    ATTRIBUTE,
    CDATA,
    COMMENT,
    TEXT,
    DOCUMENT,
    ELEMENT,
    PROCESSING_INSTR,
    BOOLEAN,
    NUMBER,
    STRING;

    public String toText() {
        return NbBundle.getMessage(ResultType.class, "ResultType." + this);
    }

    private static Map<Class<?>, ResultType> typeHeaders = new HashMap<Class<?>, ResultType>();

    static {
        typeHeaders.put(Attr.class, ResultType.ATTRIBUTE);
        typeHeaders.put(CDATASection.class, ResultType.CDATA);
        typeHeaders.put(Comment.class, ResultType.COMMENT);
        typeHeaders.put(Text.class, ResultType.TEXT);
        typeHeaders.put(Document.class, ResultType.DOCUMENT);
        typeHeaders.put(Element.class, ResultType.ELEMENT);
        typeHeaders.put(ProcessingInstruction.class, ResultType.PROCESSING_INSTR);
        typeHeaders.put(Boolean.class, ResultType.BOOLEAN);
        typeHeaders.put(Number.class, ResultType.NUMBER);
        typeHeaders.put(String.class, ResultType.STRING);
    }

    public static String formatType(Class<?> clazz) {
        Class<?> key = null;
        for (Class<?> type : typeHeaders.keySet()) {
            if (type.isAssignableFrom(clazz)) {
                key = type;
                break;
            }

        }
        if (key != null) {
            String text = typeHeaders.get(key).toText();
            return text;
        }
        return null;
    }
}
